home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Network Ne20623652001.psc / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-01-25  |  9.7 KB  |  210 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form frmNWCheck 
  4.    Caption         =   "Network Neighborhood Browser"
  5.    ClientHeight    =   6195
  6.    ClientLeft      =   5775
  7.    ClientTop       =   4320
  8.    ClientWidth     =   9045
  9.    BeginProperty Font 
  10.       Name            =   "Arial"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "Form1.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    ScaleHeight     =   6195
  21.    ScaleWidth      =   9045
  22.    Begin MSComctlLib.ImageList imlNWImages 
  23.       Left            =   0
  24.       Top             =   5280
  25.       _ExtentX        =   1005
  26.       _ExtentY        =   1005
  27.       BackColor       =   -2147483643
  28.       ImageWidth      =   16
  29.       ImageHeight     =   16
  30.       MaskColor       =   12632256
  31.       _Version        =   393216
  32.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  33.          NumListImages   =   13
  34.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  35.             Picture         =   "Form1.frx":08CA
  36.             Key             =   "directory"
  37.          EndProperty
  38.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  39.             Picture         =   "Form1.frx":0C1C
  40.             Key             =   "root"
  41.          EndProperty
  42.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  43.             Picture         =   "Form1.frx":0F6E
  44.             Key             =   "group"
  45.          EndProperty
  46.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  47.             Picture         =   "Form1.frx":12C0
  48.             Key             =   "ndscontainer"
  49.          EndProperty
  50.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  51.             Picture         =   "Form1.frx":1612
  52.             Key             =   "network"
  53.          EndProperty
  54.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  55.             Picture         =   "Form1.frx":1964
  56.             Key             =   "server"
  57.          EndProperty
  58.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  59.             Picture         =   "Form1.frx":1CB6
  60.             Key             =   "tree"
  61.          EndProperty
  62.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  63.             Picture         =   "Form1.frx":2008
  64.             Key             =   "domain"
  65.          EndProperty
  66.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  67.             Picture         =   "Form1.frx":235A
  68.             Key             =   "share"
  69.          EndProperty
  70.          BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  71.             Picture         =   "Form1.frx":26AC
  72.             Key             =   "adminshare"
  73.          EndProperty
  74.          BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  75.             Picture         =   "Form1.frx":29FE
  76.             Key             =   "printer"
  77.          EndProperty
  78.          BeginProperty ListImage12 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  79.             Picture         =   "Form1.frx":2B10
  80.             Key             =   "folder"
  81.          EndProperty
  82.          BeginProperty ListImage13 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  83.             Picture         =   "Form1.frx":2E62
  84.             Key             =   "file"
  85.          EndProperty
  86.       EndProperty
  87.    End
  88.    Begin MSComctlLib.TreeView tvwNetwork 
  89.       Height          =   5175
  90.       Left            =   0
  91.       TabIndex        =   0
  92.       Top             =   0
  93.       Width           =   8655
  94.       _ExtentX        =   15266
  95.       _ExtentY        =   9128
  96.       _Version        =   393217
  97.       HideSelection   =   0   'False
  98.       Indentation     =   176
  99.       LabelEdit       =   1
  100.       Style           =   7
  101.       Appearance      =   1
  102.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  103.          Name            =   "Arial"
  104.          Size            =   8.25
  105.          Charset         =   0
  106.          Weight          =   400
  107.          Underline       =   0   'False
  108.          Italic          =   0   'False
  109.          Strikethrough   =   0   'False
  110.       EndProperty
  111.    End
  112. Attribute VB_Name = "frmNWCheck"
  113. Attribute VB_GlobalNameSpace = False
  114. Attribute VB_Creatable = False
  115. Attribute VB_PredeclaredId = True
  116. Attribute VB_Exposed = False
  117. Option Explicit
  118. Private NetRoot As NetResource
  119. Private Sub NodeExpand(Node As MSComctlLib.Node)
  120. ' Distinguish between expansion of a network object or a file system folder as seen over the network
  121. Dim FSO As Scripting.FileSystemObject
  122. Dim NWFolder As Scripting.Folder
  123. Dim FilX As Scripting.File, DirX As Scripting.Folder
  124. Dim tNod As Node, isFSFolder As Boolean
  125. ' Remove the fake node used to force the treeview to show the "+" icon
  126. tvwNetwork.Nodes.Remove Node.Key + "_FAKE"
  127. ' If this node is marked as a share is it a proper networked directory?
  128. ' need to make this check since NDS marks some containers (wrongly, in my opinion) as shares when they're not applicable to
  129. ' file system directories (i.e. the two containers demarking NDS and Novell FileServers are marked as shares)
  130. If Node.SelectedImage = "share" Then
  131.     On Error Resume Next
  132.     Set FSO = New FileSystemObject
  133.     Set NWFolder = FSO.GetFolder(Node.Key)
  134.     If Err <> 0 Then isFSFolder = False Else isFSFolder = True
  135.     On Error GoTo 0
  136. End If
  137. If Node.SelectedImage = "folder" Or (Node.SelectedImage = "share" And isFSFolder = True) Then
  138.     ' This node is a filesystem folder seen via a network UNC path
  139.     ' Use FileSystemObjects to get files and directories since network objects (generally) can't see these
  140.     '
  141.     Set FSO = New Scripting.FileSystemObject
  142.     Set NWFolder = FSO.GetFolder(Node.Key)  ' The node's key holds the UNC path to the directory
  143.     ' Enumerate the files in this folder
  144.     ' To save any more confusion I'm not querying the system to get an icon for each file and executable
  145.     ' If there's a demand I'll do a modified version, but for the moment I'm just using a generic file icon
  146.     For Each FilX In NWFolder.Files
  147.         tvwNetwork.Nodes.Add Node.Key, tvwChild, Node.Key + "\" + FilX.Name, FilX.Name, "file", "file"
  148.     Next
  149.     ' Enumerate the folders
  150.     For Each DirX In NWFolder.SubFolders
  151.         Set tNod = tvwNetwork.Nodes.Add(Node.Key, tvwChild, Node.Key + "\" + DirX.Name, DirX.Name, "folder", "folder")
  152.         tvwNetwork.Nodes.Add tNod.Key, tvwChild, tNod.Key + "_FAKE", "FAKE", "folder", "folder"
  153.         tNod.Tag = "N"
  154.     Next
  155.     Node.Tag = "Y"
  156.     ' Search up through the tree, noting the node keys so that we can then locate the NetResource object
  157.     ' under NetRoot.
  158.     Dim pS As String, kPath() As String, nX As NetResource, i As Integer, tX As NetResource
  159.     Set tNod = Node ' Start at the node that was expanded
  160.     Do While Not tNod.Parent Is Nothing ' Proceed up the tree using parent references, each time saving the node key to the string pS
  161.         pS = tNod.Key + "|" + pS
  162.         Set tNod = tNod.Parent
  163.     Loop
  164.     ' String pS is now of the form "<Node Key>|<Node Key>|<Node Key>"
  165.     ' Split this into an array using the VB6 Split function
  166.     kPath = Split(pS, "|")
  167.     Set nX = NetRoot
  168.     ' Now loop through this array, this time following down the tree of NetResource objects from NetRoot to the child NetResource object that corresponds to
  169.     ' the node the user clicked
  170.     For i = 0 To UBound(kPath) - 1
  171.         Set nX = nX.Children(kPath(i))
  172.     Next
  173.     ' Now that we know both the node and the corresponding NetResource we can enumerate the children and add the nodes
  174.     For Each tX In nX.Children
  175.         Set tNod = tvwNetwork.Nodes.Add(nX.RemoteName, tvwChild, tX.RemoteName, tX.ShortName, LCase(tX.ResourceTypeName), LCase(tX.ResourceTypeName))
  176.         tNod.Tag = "N"
  177.         ' Add fake nodes to all new nodes except when they're printers (you can always be sure a printer never has children)
  178.         If tX.ResourceType <> Printer Then tvwNetwork.Nodes.Add tX.RemoteName, tvwChild, tX.RemoteName + "_FAKE", "FAKE", "server", "server"
  179.     Next
  180.     tvwNetwork.Refresh  ' Refresh the view
  181.     Node.Tag = "Y"  ' Set the tag to "Y" to denote that this node has been expanded and populated
  182. End If
  183. End Sub
  184. Private Sub Form_Load()
  185. ' Centre the form on the screen
  186. Me.Top = (Screen.Height - Me.Height) / 2
  187. Me.Left = (Screen.Width - Me.Width) / 2
  188. Dim nX As NetResource, nodX As Node
  189. tvwNetwork.ImageList = imlNWImages
  190. Set NetRoot = New NetResource   ' Create a new NetResource object. By default it will be the network root
  191. Set nodX = tvwNetwork.Nodes.Add(, , "_ROOT", "Entire Network", "root", "root")  ' Add a node into the tree for it
  192. nodX.Tag = "Y"  ' Set populated flag to "Y" since we populate this one immediately
  193. ' Populate the top level of objects under "Entire Network"
  194. For Each nX In NetRoot.Children
  195.     Set nodX = tvwNetwork.Nodes.Add("_ROOT", tvwChild, nX.RemoteName, nX.ShortName, LCase(nX.ResourceTypeName), LCase(nX.ResourceTypeName))
  196.     nodX.Tag = "N"  ' We haven't populated the nodes underneath this one yet, so set its flag to "N"
  197.     tvwNetwork.Nodes.Add nodX.Key, tvwChild, nodX.Key + "_FAKE", "FAKE", "server", "server" ' Create a fake node under it so that the treeview gives the "+" symbol
  198.     nodX.EnsureVisible
  199. ' You can't get printers at this level, so there's no point in enumerating the NWPrinters collections yet
  200. End Sub
  201. Private Sub Form_Resize()
  202. tvwNetwork.Width = Me.ScaleWidth
  203. tvwNetwork.Height = Me.ScaleHeight
  204. End Sub
  205. Private Sub tvwNetwork_Expand(ByVal Node As MSComctlLib.Node)
  206. If Node.Tag = "N" Then
  207.     NodeExpand Node
  208. End If
  209. End Sub
  210.